package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-02-21 23:22
 **/
public class LeetCode2181 {

    public ListNode mergeNodes(ListNode head) {
        ListNode newHead = new ListNode();
        ListNode t = head.next;
        ListNode t2 = newHead;
        int sum = 0;
        while (t != null) {
            sum += t.val;
            if (t.val == 0) {
                t2.val = sum;
                if (t.next != null) {
                    t2.next = new ListNode();
                    t2 = t2.next;
                }
                sum = 0;
            }
            t = t.next;
        }
        return newHead;
    }

}
